<template>
    <div class="refund">
        <h1>请选择退款原因</h1>
        <van-radio-group v-model="radio">
            <van-radio name="不想要了">不想要了</van-radio>
            <van-radio name="我按错了">我按错了</van-radio>
            <van-radio name="退款想买别的">退款想买别的</van-radio>
        </van-radio-group>
        <van-button :loading='loading' :disabled="!radio" class="btn" @click="submit" type="primary" size="large">提交</van-button>
        <van-tabbar route active-color="#ee0a24">
            <van-tabbar-item to="/" icon="shop-o">首页</van-tabbar-item>
            <van-tabbar-item to="/goodstypelist" icon="apps-o">全部分类</van-tabbar-item>
            <van-tabbar-item to="/shopcart" icon="shopping-cart-o">购物车</van-tabbar-item>
            <van-tabbar-item to="/center" icon="manager-o">会员中心</van-tabbar-item>
        </van-tabbar>
    </div>
</template>
<script>
import { mapState } from 'vuex'
export default {
    data(){
        return{
            radio:null,
            detail:[],
            loading:false,
        }
    },
    computed: {
        ...mapState(['openid', 'userState']),
        apiUrl() {
            return this.userState == 0 ? this.$api.merchantShow : this.$api.platformShow
        }
    },
    mounted(){
        this._get()
    },
    methods:{
        async _get() {
            let { data: { code, data } } = await this.$http.get(this.apiUrl,{
                order_code: this.$route.params.id,
                openid: this.openid
            })
            if(code === 0) {
                this.detail = data
            }
        },
        async submit(){
            let formData = new FormData()
            if (this.detail[0].shipping_status==2) {
                formData.append('refundFee', Number(this.detail[0].subtotal)+15)
            } else {
                formData.append('refundFee', this.detail[0].subtotal)
            }
            formData.append('totalFee', Number(this.detail[0].subtotal)+15)
            
            // formData.append('orderid', this.detail[0].id)
            formData.append('orderNo', this.$route.params.id)
            formData.append('openid', this.openid)
            this.loading = true
            let { data: { code, data } } = await this.$http.post(this.$api.wexinRefund,formData)
            this.loading = false
            if(code === 0 && data) {
                this.$toast(data)
                setTimeout(() => {
                    this.$router.push({
                    name: 'Center'
                    })
                }, 1500)
            }
        }
    }
}
</script>
<style lang="scss" scoped>
    .refund{
        padding: 1rem;
        h1{
            font-size: 16px;
            padding: 0.5rem 0;
        }
        .van-radio{
            padding: 0.5rem 0;
        }
        .btn{
            margin-top: 2rem;
        }
    }
</style>